package cn.fl.prjsteprebate.controller;

import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.prjsteprebate.condition.PrjStepRebateFeeQC;
import cn.fl.prjsteprebate.constant.PrjStepRebateFeeConstant;
import cn.fl.prjsteprebate.service.IPrjStepRebateFeeService;
import cn.fl.prjsteprebate.vo.PrjStepRebateFeeVO;
import cn.fl.product.service.ISplInfoService;
import cn.fl.product.vo.PrjStepRebatePaySchVO;
import cn.fl.product.vo.SplBankVO;
import cn.fl.project.condition.PrjStepSchmQueryCondition;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * @Description: 阶梯返利主表 控制层
 */
@Controller
@RequestMapping("/prjsteprebate/steprebateBscInfo")
public class PrjStepRebateFeeController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(PrjStepRebateFeeController.class);

	/**
	 * PrjStepRebateFee 服务层BEAN
	 */
	@Autowired
	private IPrjStepRebateFeeService prjStepRebateFeeService;
	/**
	 * PrdSplInfo 服务层BEAN
	 */
	@Autowired
	private ISplInfoService prdSplInfoService;
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toDetailPage", "加载例子详细页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		String isDetail = request.getParameter("isDetail");
		PrjStepRebateFeeVO prjStepRebateFeeVO = this.prjStepRebateFeeService.selectById(Long.valueOf(id));
		ModelAndView view = new ModelAndView("prjsteprebate/prjStepRebateFeeDetail");
		view.addObject("prjStepRebateFeeVO", prjStepRebateFeeVO);
		view.addObject("isDetail", isDetail);
		view.addObject("prjStepRebateFeeDetailVOs", prjStepRebateFeeVO.getPrjStepRebateFeeDetailVOList());
		List<SplBankVO> splBankVOS = this.prjStepRebateFeeService.getSplBankInfoBySplId(prjStepRebateFeeVO.getSplId());
		view.addObject("splBankVOS", splBankVOS);
		view.addObject("splBankJsons", JSON.toJSONString(splBankVOS));
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "toDetailPage", " 加载例子详细页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return view;
	}

	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String searchName = request.getParameter("demo.name");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		PrjStepRebateFeeQC qc = new PrjStepRebateFeeQC();
		if (StringUtils.isNotEmpty(searchName)) {
			//TODO SOMTHING
		}
		page.setCondition(qc);

		//TODO SOMETHING
		Pager pager = new Pager();//this.prjStepRebateFeeService.searchListPage(page);
		List<PrjStepRebateFeeVO> list = (List<PrjStepRebateFeeVO>) pager.getResultList();
		ListPageVO<PrjStepRebateFeeVO> listPage = new ListPageVO<PrjStepRebateFeeVO>(list, pager.getTotalCount());
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "initList", "加载列表页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 新增
	 */
	@RequestMapping(value = "/add.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object add(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "add", "新增对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String name = request.getParameter("name");
		DataResultDTO result = new DataResultDTO(BaseConstant.IS_YESNO_YES, "新增成功!");
		PrjStepRebateFeeVO entity = null;
		try {
			entity = this.getRequestParams(request);
			result = this.prjStepRebateFeeService.add(entity);
			//result.setData(id);
			BaseLogUtils.info(logger, "add", "新增数据返回结果 DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "add", "新增对象失败,name["+name+"].", CurrentThreadContext.getCurrentUserName(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "add", "新增对象失败,name["+name+"].", CurrentThreadContext.getCurrentUserName(), ex);
		}
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "add", "新增对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		
		return result;
	}

	/**
	 * 申请不返利
	 */
	@RequestMapping(value = "/applyNoRebate.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object applyNoRebate(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "applyNoRebate", "新增对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

		DataResultDTO result = new DataResultDTO(BaseConstant.IS_YESNO_YES, "申请不返利成功!");
		PrjStepRebateFeeVO entity = null;
		Long id = null;
		try {
			entity = this.getRequestParamsForNoRebate(request);
			id = this.prjStepRebateFeeService.applyNoRebate(entity);
			result.setData(id);
			BaseLogUtils.info(logger, "applyNoRebate", "申请不返利返回结果 DATA:" + JSONObject.toJSONString(result), CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "applyNoRebate", "申请不返利失败,name", CurrentThreadContext.getCurrentUserName(), ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "applyNoRebate", "申请不返利失败,name", CurrentThreadContext.getCurrentUserName(), ex);
		}
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "applyNoRebate", "申请不返利.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 取消不返利
	 */
	@RequestMapping(value = "/cancleNoRebate.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object cancleNoRebate(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "cancleNoRebate", "取消不返利.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		//支付表id集合
		String paySchIds = request.getParameter("paySchIds");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "取消不返利成功!");
		if(StringUtils.isEmpty(paySchIds)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("数据不存在!");
			BaseLogUtils.info(logger, "cancleNoRebate", "取消不返利,支付表id集合为空.[paySchIds="+paySchIds+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			boolean success = this.prjStepRebateFeeService.cancleNoRebate(paySchIds);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("修改失败!");
				BaseLogUtils.info(logger, "cancleNoRebate", "取消不返利失败.[paySchIds="+paySchIds+"] DATA:" , CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "cancleNoRebate", "取消不返利成功.[paySchIds="+paySchIds+"] DATA:" , CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "cancleNoRebate", "取消不返利失败,paySchIds["+paySchIds+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "cancleNoRebate", "取消不返利失败,paySchIds["+paySchIds+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}

		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "cancleNoRebate", "取消不返利.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	private PrjStepRebateFeeVO getRequestParamsForNoRebate(HttpServletRequest request) {
		PrjStepRebateFeeVO prjStepRebateFeeVO = new PrjStepRebateFeeVO();
		//总的阶梯返利金额
		String stepRebateAmt = request.getParameter("stepRebateAmt");
		//经销商id
		String splId = request.getParameter("splId");
		//经销商名称
		String splNm = request.getParameter("splNm");
		//支付表id集合
		String paySchIds = request.getParameter("paySchIds");
		//不返利原因
		String noRebateRst = request.getParameter("noRebateRst");

		prjStepRebateFeeVO.setStepRebateAmt(DecimalUtils.mul(Double.parseDouble(stepRebateAmt),100));
		prjStepRebateFeeVO.setSplId(Long.valueOf(splId));
		prjStepRebateFeeVO.setSplNm(splNm);
		prjStepRebateFeeVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		prjStepRebateFeeVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		prjStepRebateFeeVO.setPaySchIds(paySchIds);
		prjStepRebateFeeVO.setNoRebateRst(noRebateRst);
		prjStepRebateFeeVO.setApplyType(PrjStepRebateFeeConstant.APPLY_TYPE_NO_REBATE);
		return prjStepRebateFeeVO;
	}

	/**
	 * 发起供应商阶梯返利流程
	 *
	 * @param request
	 * @param response
	 * @return
	 * @throws BaseException
	 */
	@RequestMapping(value = "/addPrjStepRebateFeeFlow.do", method = {RequestMethod.POST})
	@ResponseBody
	public Object addPrjStepRebateFeeFlow(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.newLogger("addPrjStepRebateFeeFlow.发起供应商阶梯返利流程Start.请求参数:{},userNm:{}", this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName()).info();
		String accNo = request.getParameter("accNo");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "新增成功!");
		PrjStepRebateFeeVO entity = null;
		try {
			entity = this.getRequestParams(request);
			if (entity == null) {
				result = new DataResultVO(BaseConstant.IS_YESNO_NO, SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
				BaseLogUtils.newLogger("addPrjStepRebateFeeFlow.发起流程==参数为空!" + "userNm:" + CurrentThreadContext.getCurrentUserName()).info();
				return result;
			}
			BaseLogUtils.newLogger("addPrjStepRebateFeeFlow.发起流程Start=accNo:" + entity.getAccNo() + ",userNm:" + CurrentThreadContext.getCurrentUserName()).info();
			DataResultDTO resultDTO = this.prjStepRebateFeeService.addPrjStepRebateFeeFlow(entity);
			BaseLogUtils.newLogger("addPrjStepRebateFeeFlow.发起流程End=accNo:{},resultDTO:{},userNm:{}", entity.getAccNo(), JSON.toJSONString(resultDTO), CurrentThreadContext.getCurrentUserName()).info();
			result.setSuccess(resultDTO.getSuccess());
			result.setInfo(resultDTO.getInfo());
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.newLogger("addPrjStepRebateFeeFlow.发起流程异常=accNo:{},DATA:{},异常信息:{}", accNo, JSON.toJSONString(entity), e).info();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员！");
			BaseLogUtils.newLogger("addPrjStepRebateFeeFlow.发起流程异常==accNo:{},DATA:{},异常信息:{}", accNo, JSON.toJSONString(entity), e).setThrowable(e).error(LogExceptionEnum.COMMON_CODE_0002);
		}
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.newLogger("addPrjStepRebateFeeFlow.发起流程.耗时:{},userNm:{}", (endTm - startTm), CurrentThreadContext.getCurrentUserName()).info();
		return result;
	}

	private PrjStepRebateFeeVO getRequestParams(HttpServletRequest request) {
		PrjStepRebateFeeVO prjStepRebateFeeVO = new PrjStepRebateFeeVO();
		//总的阶梯返利金额
		String stepRebateAmt = request.getParameter("stepRebateAmt");
		//账号
		String accNo = request.getParameter("accNo");
		//收款方
		String rcptUnt = request.getParameter("rcptUnt");
		//开户行
		String bkNm = request.getParameter("bkNm");
		//开户行号
		String bkNo = request.getParameter("bkNo");
		//经销商id
		String splId = request.getParameter("splId");
		//经销商名称
		String splNm = request.getParameter("splNm");
		//支付表id集合
		String paySchIds = request.getParameter("paySchIds");
		if (StringUtils.isEmpty(stepRebateAmt)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "阶梯返利金额为空!");
		}
		if (StringUtils.isEmpty(accNo)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "开户行账号为空!");
		}
		if (StringUtils.isEmpty(rcptUnt)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "账户名为空!");
		}
		if (StringUtils.isEmpty(bkNm)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "开户行及支行为空!");
		}
		if (StringUtils.isEmpty(bkNo)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "开户行行号为空!");
		}
		if (StringUtils.isEmpty(paySchIds)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "支付表id为空!");
		}
		prjStepRebateFeeVO.setStepRebateAmt(DecimalUtils.mul(Double.parseDouble(stepRebateAmt),100));
		prjStepRebateFeeVO.setAccNo(accNo);
		prjStepRebateFeeVO.setRcptUnt(rcptUnt);
		prjStepRebateFeeVO.setBkNm(bkNm);
		prjStepRebateFeeVO.setBkNo(bkNo);
		prjStepRebateFeeVO.setSplId(Long.valueOf(splId));
		prjStepRebateFeeVO.setSplNm(splNm);
		prjStepRebateFeeVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		prjStepRebateFeeVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		prjStepRebateFeeVO.setPaySchIds(paySchIds);
		prjStepRebateFeeVO.setApplyType(PrjStepRebateFeeConstant.APPLY_TYPE_REBATE);
		return prjStepRebateFeeVO;
	}

	/**
	 * 得到一条记录
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());
		
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			BaseLogUtils.error(logger, "getById", "获取数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		try {
			PrjStepRebateFeeVO vo = this.prjStepRebateFeeService.selectById(Long.valueOf(id));
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在!");
				BaseLogUtils.info(logger, "getById", "获取数据,数据不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getById", "获取数据.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "getById", "根据主键获取对象失败,主键["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}
		
		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getById", "根据主键获取对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 修改
	 */
	@RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
	@ResponseBody
	public Object modify(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modify", "修改对象.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

		String id = request.getParameter("id");
		String rcptUnt = request.getParameter("rcptUnt");
		String bkNm = request.getParameter("bkNm");
		String accNo = request.getParameter("accNo");
		String bkNo = request.getParameter("bkNo");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "修改成功!");
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("数据不存在!");
			BaseLogUtils.info(logger, "modify", "修改数据,主键不存在.[id="+id+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}
		PrjStepRebateFeeVO entity = null;
		try {
			entity = new PrjStepRebateFeeVO();
			entity.setId(Long.valueOf(id));
			entity.setBkNo(bkNo);
			entity.setBkNm(bkNm);
			entity.setAccNo(accNo);
			entity.setRcptUnt(rcptUnt);
			entity.setMdfTm(new Date());
			entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
			boolean success = this.prjStepRebateFeeService.modify(entity);
			if(!success){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("修改失败!");
				BaseLogUtils.info(logger, "modify", "修改失败.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
			}
			BaseLogUtils.info(logger, "modify", "修改成功.[id="+id+"] DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "modify", "修改对象失败,id["+id+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}

		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "modify", "修改对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 根据供应商id、支付表集合（包含支付表号、融资额字段）查询阶梯返利金额
	 *
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getStepRebateFee.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getStepRebateFee(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getStepRebateFee", "查询阶梯返利金额.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

		String splId = request.getParameter("splId");
		String paySchs = request.getParameter("paySchs");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(splId) || StringUtils.isEmpty(paySchs)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请求参数为空!");
			BaseLogUtils.error(logger, "getStepRebateFee", "查询阶梯返利金额,请求参数为空！", CurrentThreadContext.getCurrentUserName());
			return result;
		}

		try {
			PrjStepRebateFeeVO vo = this.prjStepRebateFeeService.getStepRebateFee(splId,paySchs);
			BaseLogUtils.info(logger, "getStepRebateFee", "查询阶梯返利金额,返回数据:[result="+JSON.toJSONString(vo)+"]", CurrentThreadContext.getCurrentUserName());
			if(null == vo){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在!");
				BaseLogUtils.info(logger, "getStepRebateFee", "查询阶梯返利金额,数据不存在.[splId="+splId+"],[paySchs="+paySchs+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(vo);
			BaseLogUtils.info(logger, "getStepRebateFee", "查询阶梯返利金额成功.[splId="+splId+"],[paySchs="+paySchs+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getStepRebateFee", "查询阶梯返利金额失败,[splId="+splId+"],[paySchs="+paySchs+"]", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "getStepRebateFee", "查询阶梯返利金额失败,[splId="+splId+"],[paySchs="+paySchs+"]", CurrentThreadContext.getCurrentUserName(),ex);
		}

		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getStepRebateFee", "根据主键获取对象.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());

		return result;
	}

	/**
	 * 根据供应商id查询开户行等银行信息
	 *
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getSplBankInfoBySplId.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object getSplBankInfo(HttpServletRequest request, HttpServletResponse response) throws BaseException {
		Long startTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getSplBankInfoBySplId", "根据供应商id获取银行账号相关信息.请求参数：" + this.getRequestParameter(request), CurrentThreadContext.getCurrentUserName());

		String splId = request.getParameter("splId");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "操作成功!");
		if(StringUtils.isEmpty(splId)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("主键不能为空!");
			BaseLogUtils.error(logger, "getSplBankInfoBySplId", "根据供应商id获取银行账号相关信息,供应商不存在.[splId="+splId+"]", CurrentThreadContext.getCurrentUserName());
			return result;
		}

		try {
			List<SplBankVO> splBankVOS = this.prjStepRebateFeeService.getSplBankInfoBySplId(Long.valueOf(splId));
			if(null == splBankVOS){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("数据不存在!");
				BaseLogUtils.info(logger, "getSplBankInfoBySplId", "根据供应商id获取银行账号相关信息,供应商数据不存在.[splId="+splId+"]", CurrentThreadContext.getCurrentUserName());
			}
			result.setData(splBankVOS);
			BaseLogUtils.info(logger, "getSplBankInfoBySplId", "根据供应商id获取银行账号相关信息.[splId="+splId+"]", CurrentThreadContext.getCurrentUserName());
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getSplBankInfoBySplId", "根据供应商id获取银行账号相关信息失败,供应商id["+splId+"].", CurrentThreadContext.getCurrentUserName(),ex);
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误,请联系管理员!");
			BaseLogUtils.error(logger, "getSplBankInfoBySplId", "根据供应商id获取银行账号相关信息失败,供应商id["+splId+"].", CurrentThreadContext.getCurrentUserName(),ex);
		}

		Long endTm = System.currentTimeMillis();
		BaseLogUtils.info(logger, "getSplBankInfoBySplId", "根据供应商id获取银行账号相关信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
		return result;
	}

	/**
	 * 跳转到供应商阶梯返利页面
	 * @return
	 */
	@RequestMapping(value = "/toPaySchApplyRebatePage.do",method= RequestMethod.GET)
	public ModelAndView toPaySchApplyRebate(){
		ModelAndView view = new ModelAndView("project/prjsplrebate/paySchListForSplRebate");
		List<KeyValueVO> searchBuOrgList = this.prdSplInfoService.searchBuOrgCdList();
		view.addObject("searchBuOrgList", searchBuOrgList);
		return view ;
	}

    @ResponseBody
    @RequestMapping(value = "/getPrjStepSchmList.do", method = {RequestMethod.GET, RequestMethod.POST})
    public Object searchPrjStepSchmList(HttpServletRequest request, @RequestBody PrjStepSchmQueryCondition condition) {
        BaseLogUtils.newLogger("查询经销商阶梯返利页面支付表列表,查询条件:{}", JSON.toJSONString(condition)).info();
        JSONObject jsonObject = new JSONObject();
        try{
            Pager pager = new Pager();
            pager.setCurrentPage(condition.getPage());
            pager.setEveryPage(condition.getPagesize());
            pager.setCondition(condition);
            pager = prjStepRebateFeeService.searchPrjStepSchmList(pager);
            BaseLogUtils.newLogger("查询经销商阶梯返利页面支付表列表,查询结果:{}", JSON.toJSONString(pager)).info();
            if (pager == null || CollectionUtils.isEmpty(pager.getResultList())){
                return null;
            }
            Double totalLsAmt = 0d;
            List<PrjStepRebatePaySchVO> list = (List<PrjStepRebatePaySchVO>) pager.getResultList();
            ListPageVO<PrjStepRebatePaySchVO> listPage = new ListPageVO<PrjStepRebatePaySchVO>(list, pager.getTotalCount());
            for (PrjStepRebatePaySchVO vo : list) {
                totalLsAmt += vo.getActLsAmt();
            }
            jsonObject.put("totalLsAmt", totalLsAmt); // 总融资额
            jsonObject.put("rows", listPage.getRows()); // 支付表列表
            jsonObject.put("total", listPage.getTotal()); // 支付表列表
        }catch (Exception e){
            BaseLogUtils.newLogger("查询支付表列表失败").setThrowable(e).error(LogExceptionEnum.API_CODE_0101);
			jsonObject.put("totalLsAmt", 0); // 总融资额
			jsonObject.put("rows", null); // 支付表列表
			jsonObject.put("total", 0); // 支付表列表
            return jsonObject;
        }
        return jsonObject;
    }
}

